package com.lry.crawlers.comic.service.impl;

import com.lry.crawlers.comic.entity.ComicVariable;
import com.lry.crawlers.comic.mapper.ComicVariableMapper;
import com.lry.crawlers.comic.service.ComicVariableService;
import com.lry.crawlers.util.ProcessVariable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;

@Service
public class ComicVariableServiceImpl implements ComicVariableService {
    @Autowired
    ComicVariableMapper comicVariableMapper;
    //初始化ComicVariable信息
    @PostConstruct
    private void initialize() {
        List<ComicVariable> comicVariables = getComicVariables();
        for (ComicVariable c: comicVariables){
            ProcessVariable.setCVariable(c.getId(),c);
        }

    }

    public void update(){
        initialize();
    }

    @Override
    public int setComicVariable(ComicVariable comicVariable) {
        int insert = comicVariableMapper.insert(comicVariable);
        return insert;
    }

    @Override
    public List<ComicVariable> getComicVariables() {
        return comicVariableMapper.selectList(null);
    }

}
